import { defineStore } from 'pinia'
import { reactive, watch } from 'vue'

export const useSettingStore = defineStore('setting', () => {
    const settings = reactive({})

    function init(data) {
        for (let key in data) {
            settings[key] = data[key]
        }
    }

    function setSetting(key, value) {
        settings[key] = value
        $store.setSetting(key, value)
    }

    // 监听主题设置的变化并做出改变
    watch(
        () => settings.theme,
        (value) => {
            $theme.change(value)
        }
    )

    return { settings, init, setSetting }
})
